package com.zblog.yuhang.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.zblog.yuhang.domain.Blog;
import com.zblog.yuhang.service.BlogService;

@Controller
public class MainController {

	@Autowired
	BlogService blogService;
	
	@GetMapping("/")
	public String root() {
		return "redirect:/index";
	}
	
	@GetMapping("/index")
	public ModelAndView showIndex(Model model){
		List<Blog> blogs = blogService.getAllBlog();
		model.addAttribute("blogs", blogs);
		model.addAttribute("title", "Blogs");
		return new ModelAndView("index", "model", model);
	}
	
	@GetMapping("/login")
	public String login() {
		return "login";
	}

	
	
}
